﻿using System;

namespace MyFramework.Core
{
    /// <summary>
    /// exception handler
    /// </summary>
    public static class ExceptionHandler
    {
        /// <summary>
        /// Handles the with exception handler.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="exceptionWrapper">The exception wrapper.</param>
        /// <param name="exceptionHandler">The exception handler.</param>
        /// <returns></returns>
        public static bool HandleWithExceptionHandler(ref Exception exception, Func<Exception, Exception> exceptionWrapper, Func<Exception, bool> exceptionHandler)
        {
            var handled = false;

            if (!(exception is ControllerException) && exceptionWrapper != null)
            {
                exception = exceptionWrapper(exception);
            }

            if (exceptionHandler != null)
            {
                handled = exceptionHandler(exception);
            }

            return handled;
        }
    }
}
